package edu.pku.sei.autounit.generator;

import java.util.Iterator;

import edu.pku.sei.autounit.core.Variable;
import edu.pku.sei.autounit.core.VariableFactory;
import edu.pku.sei.autounit.core.VariableGenerator;
import edu.pku.sei.autounit.filter.Filter;
import edu.pku.sei.autounit.reflect.Class;
import edu.pku.sei.autounit.reflect.Constructor;
import edu.pku.sei.autounit.reflect.Interface;
import edu.pku.sei.autounit.reflect.Type;
import edu.pku.sei.autounit.util.NameFactory;

public class InterfaceGenerator implements VariableGenerator{

	
	public Variable generate(Type type, String name, VariableFactory vf,
			NameFactory nf) {
		if(!(type instanceof Interface))
			return null;
		Interface inter = (Interface)type;
		Iterator<Class> it = inter.getSubClasses();
		while(it.hasNext()){
			Class t = it.next();
			if(t.canInstantiation()){
				Constructor constructor = null;
				int min = 100;
				for(Constructor con:t.getPublicConstructors()){
					if(con.getParameters().length<min){
						min = con.getParameters().length;
						constructor = con;
						if(min == 0)
							break;
					}
				}
				return new ConstructorInvoke(type,name,constructor,vf,nf);
			}
		}
		return null;
	}

	
	public Variable generate(Type type, String name, Filter fliter,
			VariableFactory vf, NameFactory nf) {
		// TODO Auto-generated method stub
		return null;
	}

}
